package com.example.foobar.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.example.foobar.entity.DidiOrders;
import com.example.foobar.mapper.DidiOrdersMapper;
import com.example.foobar.dao.service.DidiOrdersDaoService;
import com.example.foobar.param.DidiDateParam;
import com.example.foobar.param.DidiOrdersPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.foobar.vo.DidiData;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 滴滴订单 服务实现类
 *
 * @author 郑英奔
 * @since 2021-10-26
 */
@Slf4j
@Service
public class DidiOrdersDaoServiceImpl extends BaseServiceImpl<DidiOrdersMapper, DidiOrders> implements DidiOrdersDaoService {

    @Autowired
    private DidiOrdersMapper didiOrdersMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDidiOrders(DidiOrders didiOrders) throws Exception {
        return super.save(didiOrders);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDidiOrders(DidiOrders didiOrders) throws Exception {
        return super.updateById(didiOrders);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDidiOrders(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<DidiOrders> getDidiOrdersPageList(DidiOrdersPageParam didiOrdersPageParam) throws Exception {
        Page<DidiOrders> page = new PageInfo<>(didiOrdersPageParam, OrderItem.desc(getLambdaColumn(DidiOrders::getCreateTime)));
        LambdaQueryWrapper<DidiOrders> wrapper = new LambdaQueryWrapper<>();
        IPage<DidiOrders> iPage = didiOrdersMapper.selectPage(page, wrapper);
        return new Paging<DidiOrders>(iPage);
    }

    @Override
    public IPage<DidiData> getDidiDateList(Page page, DidiDateParam didiDateParam) {
        return didiOrdersMapper.getDidiDateList(page, didiDateParam);
    }

}
